package com.huluobo.a2204monthparkdemo

import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.util.Log
import android.view.View
import android.webkit.JavascriptInterface
import android.widget.ImageView
import com.blankj.utilcode.util.SPUtils
import com.huluobo.a2204monthparkdemo.news.NewsActivity
import com.huluobo.a2204monthparkdemo.parking.ParkingActivity
import com.huluobo.a2204monthparkdemo.repair.RepairActivity
import com.huluobo.a2204monthparkdemo.sign.SignActivity
import com.huluobo.a2204monthparkdemo.sign.SignMonthActivity
import com.huluobo.a2204monthparkdemo.utils.WebViewJavaScriptFunction
import com.huluobo.a2204monthparkdemo.utils.X5WebView
import com.huluobo.a2204monthparkdemo.visitor.VisitorActivity
import com.huluobo.base.net.Const
import com.tencent.smtt.sdk.WebView

class MainActivity : AppCompatActivity() {
    private lateinit var url: String
    private lateinit var x5WebView: WebView
    private lateinit var listener: MainWebViewJavaScriptFun
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        url = SPUtils.getInstance().getString(Const.PARAM_HOME)
        initWebView()
        findViewById<ImageView>(R.id.header_back).visibility = View.GONE
    }

    private fun initWebView() {
        listener = MainWebViewJavaScriptFun()
        x5WebView = findViewById(R.id.main_x5)
        x5WebView.loadUrl(url)
        x5WebView.view.overScrollMode = View.OVER_SCROLL_ALWAYS
        x5WebView.addJavascriptInterface(listener, "androidinfo")
    }

    inner class MainWebViewJavaScriptFun : WebViewJavaScriptFunction {
        @JavascriptInterface
        fun androidsign(id: String) {
            start(SignActivity::class.java)
        }

        @JavascriptInterface
        fun androidaddculture(id: String) {
            //打开新闻activity
            start(NewsActivity::class.java)
        }

        @JavascriptInterface
        fun androidparking(id: String?) {
            //车位申请
            start(ParkingActivity::class.java)
        }

        @JavascriptInterface
        fun androidapply(id: String?) {
            //我的申请
            Log.i("TagA", "我的申请")
        }

        @JavascriptInterface
        fun androidvisit(id: String?) {
            //来访预约
            start(VisitorActivity::class.java)
        }

        @JavascriptInterface
        fun androidpatrol(id: String?) {
            //巡更管理
            Log.i("TagA", "巡更管理")
        }

        @JavascriptInterface
        fun androidnews(id: String?) {
            Log.i("TagA", "新闻")
        }

        @JavascriptInterface
        fun androidnoticelist(id: String?) {
            Log.i("TagA", "通知列表")
        }

        @JavascriptInterface
        fun androidrepair(id: String?) {
            //维修管理
            start(RepairActivity::class.java)

        }

        @JavascriptInterface
        fun androidaddrepair(id: String?) {
            //添加维修
            Log.i("TagA", "添加维修")
        }

        @JavascriptInterface
        fun androidaddnotice(id: String?) {
            //公告管理
            Log.i("TagA", "添加公告")

        }

        @JavascriptInterface
        fun androidculture(id: String?) {
            //文化管理
            Log.i("TagA", "文化管理")

        }

        @JavascriptInterface
        fun androidnotice(id: String?) {
            //公告管理
            Log.i("TagA", "公告管理")

        }

        @JavascriptInterface
        fun androidattendance(id: String?) {
            //考勤管理
            start(SignMonthActivity::class.java)

        }

        @JavascriptInterface
        fun androidproperty(id: String?) {
            //物业审核
            Log.i("TagA", "物业审核")

        }

        @JavascriptInterface
        fun androidcheckculture(id: String?) {
            //文化审核
            Log.i("TagA", "文化审核")

        }

        @JavascriptInterface
        fun androidpeople(id: String?) {
            //人资管理
            Log.i("TagA", "人资管理")

        }
    }

    private fun start(clazz: Class<*>) {
        val intent = Intent(this, clazz)
        startActivity(intent)
    }
}